package com.ews.onlineexchange.controller.pub;

import com.ews.onlineexchange.model.Advice;
import com.ews.onlineexchange.service.EntityHome;

import javax.enterprise.inject.Model;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 * @program: SdewsOnlineExchange_dys
 * @description:
 * @author: wangchangqing
 * @create: 2021-03-11 11:21
 **/

@Model
public class AdviceHome extends EntityHome<Advice,String> {

    @Override
    public String saveAndFlush() {
        HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String ip = request.getRemoteAddr();
        getInstance().setIp(ip);
        super.saveAndFlush();
        FacesContext.getCurrentInstance().addMessage("",new FacesMessage(FacesMessage.SEVERITY_INFO, "提交成功！", ""));
        setInstance(new Advice());
        return "ok";
    }
}
